﻿using System;
using System.ComponentModel;
using System.Runtime.Serialization;

namespace Entities
{
    [Serializable]
    [DataContract]
    public class EntityBase : INotifyPropertyChanged
    {
        ~EntityBase()
        {
            PropertyChanged = null;
        }       

        private int _Id;
// ReSharper disable VirtualMemberNeverOverriden.Global
        [DataMember] public virtual int ID
// ReSharper restore VirtualMemberNeverOverriden.Global
        {
            get
            {
                return _Id;
            }
            set
            {
                if (_Id == value) return;
                _Id = value;
                OnPropertyChanged("ID");
            }
        }

        #region INotifyPropertyChanged Members

        /// <summary>
        /// Occurs when a property value changes.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion
    }
}
